/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DSB.Utilities;

import DSB.Controller.ToeristController;
import java.awt.Component;
import java.awt.Container;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;

/**
 *
 * @author Gebruiker
 */
public class Utilities {
    private static List<Component> getAllComponents(final Container c) {
        Component[] comps = c.getComponents();
        List<Component> compList = new ArrayList<>();
        for (Component comp : comps) {
            compList.add(comp);
            if (comp instanceof Container) {
                compList.addAll(getAllComponents((Container) comp));
            }
        }
        return compList;
    }

    /**
     *
     * @param container
     */
    public static void TranslateScreen(Container container)
    {
        JFrame screen = (JFrame) container;
        String mainText = ToeristController.getInstance().GetResource(screen.getName());
        screen.setTitle(mainText);
        
        for (Component c : getAllComponents(container))
        {
            if(c instanceof JTextField)
            {
                JTextField field  = (JTextField) c;
                String text1 = ToeristController.getInstance().GetResource(field.getName());
                field.setText(text1);
            }
            
            if(c instanceof JLabel)
            {
                JLabel label  = (JLabel) c;
                String text1 = ToeristController.getInstance().GetResource(label.getName());
                label.setText(text1);
            }
            
            if(c instanceof JButton)
            {
                JButton button  = (JButton) c;
                String text1 = ToeristController.getInstance().GetResource(button.getName());
                button.setText(text1);
            }

            if(c instanceof JMenu)
            {
                JMenu menu = (JMenu) c;
                String text2 = ToeristController.getInstance().GetResource(menu.getName());
                menu.setText(text2);

                for(int a=0; a < menu.getMenuComponentCount(); a++)
                {                               
                    JMenuItem item = (JMenuItem) menu.getMenuComponent(a);
                    String name = item.getName();
                    String subtext = ToeristController.getInstance().GetResource(name);
                    item.setText(subtext);
                }
            }
        }
    }
}
